import threadpool.Priority;
import threadpool.PriorityExecutor;
import threadpool.PriorityRunnable;

import java.util.concurrent.ExecutorService;
/**
 * ThreadPoolExecutor自定义线程池
 * 内容都在threadpool包里
 */
public class Demo02ThreadPoolExecutor {
    public static void main(String[] args) {
        ExecutorService executorService = new PriorityExecutor(5, false);

        for (int i = 0; i < 20; i++) {
            //任务
            PriorityRunnable priorityRunnable = new PriorityRunnable(Priority.NORMAL, new Runnable() {
                @Override
                public void run() {
                    System.out.println(Thread.currentThread().getName()+"优先级正常");
                }
            });
            if (i % 3 == 1) {
                priorityRunnable = new PriorityRunnable(Priority.HIGH, new Runnable() {
                    @Override
                    public void run() {
                        System.out.println(Thread.currentThread().getName()+"优先级高");
                    }
                });
            } else if (i % 5 == 0) {
                priorityRunnable = new PriorityRunnable(Priority.LOW, new Runnable() {
                    @Override
                    public void run() {
                        System.out.println(Thread.currentThread().getName()+"优先级低");
                    }
                });
            }
            executorService.execute(priorityRunnable);
        }
    }
}
